// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

#include "Import/BDFImport/BulkData/Coordinate/CORD2RParser.h"

#include "gtest/gtest.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Coordinate/ICORD2RService.h"

#include "Import/BDFImport/BDFParserBase.h"
using namespace SG::DBManager;
using namespace SG::Import;
using SG::DataStructure::Common::TOLERANCE;
using namespace SG::DataStructure::FEM;
extern std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY;
extern std::vector<std::string>          dividedEntryInfo;

class CORD2RParserTest : public ::testing::Test
{
  public:
    static void SetUpTestSuite ()
    {
        DB_SERVICEFACTORY->ClearDatabase ();
    }
};

TEST_F (CORD2RParserTest, ParseEntry1)
{
    std::vector<std::string> Entry = { "CORD2R*  410101                          2375.45         14443.9",
                                       "*        -499.777       15741.666528951220384.3851241174 257.63910331433",
                                       "*       -193.5207067796521805.0094553287-12898.698084377",
                                       "*" };

    BDF::divideBulkEntry (Entry, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParseCORD2R (DB_SERVICEFACTORY, dividedEntryInfo);

    SG::DataStructure::FEM::CORD2RData data;
    ASSERT_EQ (
        true, DB_SERVICEFACTORY->get<ICORD2RService> ()->FindById (410101, _OUT data) == SG::DataStructure::Common::Status::STATUS_Success);
    ASSERT_TRUE (data.m_id == 410101);
    ASSERT_NEAR (data.m_a1, 2375.45, TOLERANCE);
    ASSERT_NEAR (data.m_a2, 14443.9, TOLERANCE);
    ASSERT_NEAR (data.m_a3, -499.777, TOLERANCE);
    ASSERT_NEAR (data.m_b1, 15741.6665289512, TOLERANCE);
    ASSERT_NEAR (data.m_b2, 20384.3851241174, TOLERANCE);
    ASSERT_NEAR (data.m_b3, 257.63910331433, TOLERANCE);
    ASSERT_NEAR (data.m_c1, -193.52070677965, TOLERANCE);
    ASSERT_NEAR (data.m_c2, 21805.0094553287, TOLERANCE);
    ASSERT_NEAR (data.m_c3, -12898.698084377, TOLERANCE);
}

/* TEST_F (CORD2RParserTest, ParseFile)
{
    std::string                     BDFFilePath = "TestData/demo5yue.bdf";  // 需要改
    SG::Import::IFEMImporterSP BDFImp      = std::make_shared<SG::Import::BDF::BDFImport> (DB_SERVICEFACTORY);
    BDFImp->Load (BDFFilePath.c_str ());
} */
